#ifndef Net_TcpServer_INCLUDED
#define Net_TcpServer_INCLUDED

#include "serversocket.h"
#include "tcpserverconnection.h"
#include "runnable.h"
#include "thread.h"
#include "threadpool.h"

class TcpServerDispatcher;

class TcpServer: public Runnable
{
public:
    TcpServer(TcpServerConnectionFactory* pFactory, ThreadPool& threadPool,
            const ServerSocket& socket);

    virtual ~TcpServer();

    void start();

    void stop();

    ServerSocket& socket();

    unsigned int port();

protected:
    void run();

private:
    TcpServer();
    TcpServer(const TcpServer&);
    TcpServer& operator = (const TcpServer&);

private: 
    ServerSocket                m_socket;
    TcpServerDispatcher*        m_pDispatcher;
    Thread                      m_thread;
    bool                        m_stopped;
};

inline ServerSocket& TcpServer::socket()
{
    return m_socket;
}

inline unsigned int TcpServer::port()
{
    return m_socket.address().port();
}

#endif 







